package com.example.administrator.myweiyue.utils;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.example.administrator.myweiyue.R;


public class DialogHelper {
    public static AlertDialog getLoadingDialog(Context context) {
        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
//        alertDialog.show();            //alertDialog.cancel();关闭
        Window win = alertDialog.getWindow();
        // 点击外部区域不会消失
        alertDialog.setCanceledOnTouchOutside(false);
        //外部区域颜色不变淡

        //设置窗口透明#00000000，要不出问题
        win.setBackgroundDrawableResource(R.color.color_tran);
        WindowManager.LayoutParams lp = win.getAttributes();
        win.setGravity(Gravity.CENTER);//最终位置Gravity.LEFT | Gravity.BOTTOM，，，，，top,right,中间
        // lp.alpha = 0.7f;//改变的是整个窗口，最好不要
        lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;//宽和屏幕宽一样
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;//设置dialog高度为包裹内容
        //lp.x =-80向左偏移80，lp.y =-60上偏移60
        win.getDecorView().setPadding(0, 0, 0, 0);//去padding，要不然不会跟父窗体一样宽
//增加一点视觉效果
        win.clearFlags
                (WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        win.setAttributes(lp);
        win.setContentView(R.layout.dialog);
//找到里面的控件
        return alertDialog;
    }
}
